﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Tauren.Business.Entity.Global;
using Tauren.Business.Entity.Output;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.Menus;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 菜单信息
    /// </summary>
    [Route("api/menu"), ApiVersion("1.0")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private IMenuService service { get; set; }
        /// <summary>
        /// 菜单信息
        /// </summary>
        public MenuController(IMenuService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 获取所有数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/menus")]
        public IActionResult Menus() => service.Menus().ToJsonResult();
        /// <summary>
        /// 获取所有数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/tables")]
        public IActionResult Tables() => service.Tables().ToJsonResult();
        /// <summary>
        /// 新增菜单信息
        /// </summary>
        /// <param name="input">菜单信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.Menus_InPut input) => service.Add(input).ToJsonResult();


        /// <summary>
        /// 编辑菜单信息
        /// </summary>
        /// <param name="input">菜单信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/editor")]
        public IActionResult Editor([FromBody] Entity.Input.Menus_InPut input) => service.Editor(input).ToJsonResult();

        /// <summary>
        /// 获取单个菜单信息数据
        /// </summary>
        /// <param name="id">菜单实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/singe/{id}")]
        public IActionResult Get([FromRoute] int id) => service.FirstOrDefault(id).ToJsonResult();

        /// <summary>
        /// 删除菜单信息
        /// </summary>
        /// <param name="id">菜单实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] long id) => service.Delete(id).ToJsonResult();

        /// <summary>
        /// 启用??
        /// </summary>
        /// <param name="id">菜单ID</param> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id:int}")]
        public IActionResult Enable(int id) => service.Enable(id).ToJsonResult();
        /// <summary>
        /// 树形菜单
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/tree")]
        public IActionResult Tree() => service.Tree().ToJsonResult();

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <param name="id">菜单实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/roles/{id}")]
        public IActionResult Roles([FromRoute] long id) => service.Roles(id).ToJsonResult();

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="_Roles"></param>
        /// <returns></returns> 

        [HttpPost, Route("v{version:apiVersion}/addroles/{menuId}")]
        public IActionResult AddRoles([FromBody] List<ExtMenus_Roles> _Roles, [FromRoute] long menuId) => service.AddRoles(_Roles, menuId).ToJsonResult();
        /// <summary>
        /// 获取所有数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();
    }
}
